using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MagPanelTest
{
public partial class PartialMagPicPanel : UserControl
{
public PartialMagPicPanel()
{
InitializeComponent();
}
private void PartialMagPicPanel_Load(object sender, EventArgs e)
{
IntPtr dc;
IntPtr region;
IntPtr hpen2;
IntPtr holdpen;
dc = GetDC(this.Handle);
BeginPath(dc);
hpen2 = CreatePen(5, 5, ColorTranslator.ToWin32(Color.Red));
holdpen = (IntPtr)SelectObject(dc, hpen2);
Ellipse(dc, 0, 0, this.Width, this.Height);
DeleteObject(hpen2);
EndPath(dc);
region = PathToRegion(dc);
SetWindowRgn(this.Handle, region, true);
}
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr BeginPath(IntPtr hdc);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern int SetBkMode(IntPtr hdc,int nBkMode);
const int TRANSPARENT = 1;
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr EndPath(IntPtr hdc);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr PathToRegion(IntPtr hdc);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr CreatePen(int fnPenStyle,int nWidth,int COLORREF);
[System.Runtime.InteropServices.DllImport("gdi32")]
public static extern IntPtr CreateSolidBrush(Int32 crColor);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr SelectObject(IntPtr hdc, IntPtr hpen);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr DeleteObject(IntPtr hpen);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern int Ellipse(IntPtr hdc, int X1, int Y1, int X2, int Y2);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern int SetWindowRgn(IntPtr hwnd, IntPtr hRgn, bool bReDraw);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr GetDC(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("gdi32")]
static extern int SetROP2(System.IntPtr hdc, int rop);
[System.Runtime.InteropServices.DllImport("gdi32")]
static extern int MoveToEx(IntPtr hdc, int x, int y, IntPtr lppoint);
[System.Runtime.InteropServices.DllImport("gdi32")]
static extern int LineTo(IntPtr hdc, int X, int Y);
}
}
放大镜
评论